home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 10 / 010.d81 / dos #26 < prev    next >
Text File  |  2022-08-26  |  2KB  |  89 lines

  1.  
  2.       DOS and don'ts -- Part 26
  3.           by Jimmy Weiler
  4.  
  5.  
  6.   Now let's get into some READing.
  7.  
  8. Reading from a RELative file is almost
  9.  
  10. the same as writing to it.  The most
  11.  
  12. significant difference is that you use
  13.  
  14. INPUT# or GET# in place of PRINT#.
  15.  
  16.  
  17.   The technique you use is:
  18.  
  19. 1. Send a position command to access
  20.    a particular record and character.
  21.  
  22. 2. Input from the file.
  23.  
  24.  
  25.   Let's read the name and number out
  26.  
  27. of record 2.
  28.  
  29. 10 OPEN 15,8,15
  30. 20 OPEN 3,8,4,"PHONEFILE,L,"+CHR$(89)
  31. 30 RN=2:rem record number
  32. 40 HB=INT (RN/256):rem high & low byte
  33. 50 LB=RN-(HB*256) :rem of record #'s
  34. 60 PRINT#15,"P"CHR$(4)CHR$(LB)CHR$(HB)
  35.    CHR$(1):rem position to rec RN
  36. 70 INPUT#3,NAME$   :rem input name and
  37. 80 INPUT#3,NUMBER$ :rem       address
  38. 90 CLOSE3
  39. 100 PRINT NAME$"'s phone number is ";
  40.     NUMBER$;"."
  41. 110 CLOSE15
  42.  
  43.  
  44. This technique works fine for reading
  45.  
  46. a record that has no commas, quotes,
  47.  
  48. or colons in its text.  If you had to
  49.  
  50. be able to read past those separators,
  51.  
  52. you would use GET# instead of INPUT#.
  53.  
  54.  
  55. 70 NAME$=""
  56. 71 GET#3,T$:IF T$<>CHR$(13)THEN NAME$=
  57.    NAME$+T$:GOTO 71
  58. 80 NUMBER$=""
  59. 81 GET#3,T$:IF T$<>CHR$(13)THEN
  60.    NUMBER$=NUMBER$+T$:GOTO 81
  61.  
  62.  
  63.   You may have noticed that we only
  64.  
  65. used one POSITION command to do an
  66.  
  67. INPUT# from our PHONEFILE.  Unlike
  68.  
  69. PRINT#, INPUT# keeps track of where
  70.  
  71. it is in a record.  Every INPUT#
  72.  
  73. begins where the previous one left off
  74.  
  75. and reads data from the file until it
  76.  
  77. comes to the next carriage return.
  78.  
  79.   INPUT# also accepts multiple
  80.  
  81. variable arguments -- you can use
  82.  
  83. INPUT#3,A$:INPUT#3,B$ or INPUT#3,A$,B$
  84.  
  85. and achieve the same effect.
  86.  
  87.  
  88. ------ continued in Part 27 ---------
  89.